/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clases;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author Miguel
 */
public class Seleccion implements ListSelectionListener{	

    ListSelectionModel modelo;	

    public Seleccion(ListSelectionModel lsm){	
        modelo = lsm; 
    }	

    @Override
    public void valueChanged(ListSelectionEvent e) {
//        throw new UnsupportedOperationException("Not supported yet.");
//        modelo.removeListSelectionListener(this);
        ListSelectionModel lsm = (ListSelectionModel) e.getSource();

      int firstIndex = e.getFirstIndex();
      int lastIndex = e.getLastIndex();
      boolean isAdjusting = e.getValueIsAdjusting();
        System.out.println("Event for indexes " + firstIndex + " - " + lastIndex
          + "; isAdjusting is " + isAdjusting + "; selected indexes:");

      if (lsm.isSelectionEmpty()) {
        System.out.println(" <none>");
      } else {
        // Find out which indexes are selected.
        int minIndex = lsm.getMinSelectionIndex();
        int maxIndex = lsm.getMaxSelectionIndex();
        for (int i = minIndex; i <= maxIndex; i++) {
          if (lsm.isSelectedIndex(i)) {
            System.out.println(" " + i);
          }
        }
      }
      System.out.println();
      System.out.println("----------------------");
    }
    
    
} 
